package com.linghu.controller;




import com.linghu.bean.Furn;
import com.linghu.bean.Msg;
import com.linghu.service.FurnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @author 令狐荣豪
 * @version 1.0
 */
@Controller
public class FurnController {
    //属性
    @Autowired
    FurnService furnService;


    @PostMapping("/save")//前端数据打到这里来
    @ResponseBody
    public Msg save(@RequestBody Furn furn){//将前端发过来的json数据封装成javabean数据
        furnService.save(furn);
        return Msg.success();
    }

    @ResponseBody
    @RequestMapping("/list")
    public Msg listAll(){
        List<Furn> furns = furnService.listAll();
        return Msg.success().add("furns",furns);
    }


    @ResponseBody
    @RequestMapping("/update")
    public Msg update(@RequestBody Furn furn){
        furnService.update(furn);
        return Msg.success();
    }


    @ResponseBody
    @RequestMapping("/zuoye/{id}")
    public Msg findById(@PathVariable Integer id){
        Furn furn = furnService.findById(id);
        return Msg.success().add("furn",furn);
    }


    @ResponseBody
    @RequestMapping("/del/{id}")
    public Msg del(@PathVariable Integer id){
        int delId = furnService.del(id);
        if (delId>0){
            return Msg.success();
        }
        return Msg.fail();
    }


}
